page.pageInit = function(){
  //初始化tree
  TreeCtr.treeInit("#sysResourcesTree");
  //初始化grid
  MainGirdCtr.gridInit();
  MainGirdCtr.buttonBind()
}

var TreeCtr = $.extend({},defaultZtreeConFig,{
	setting:{
		view: {
			selectedMulti: false
		},
		async: {
			enable: true,
			url:contextPath+"/depot/warehouse/warehouseTree.htm",
			autoParam:["id", "name=n", "level=lv"],
			otherParam:{"otherParam":"zTreeAsyncTest"},
		    dataType:"json"
		},
		callback: {
			onClick: function(e,id,node){
			  var materialId = $("#materialId").val();
			   //主GIRD刷新
			   MainGirdCtr.gridQuery({warchouseId:node.id,materialId:materialId});
			}
		}
	}
});

//grid控制器
var MainGirdCtr =  $.extend({},defaultGridConFig,{
   gridInit: function(){
	 var _this = this;
	//创建jqGrid组件
	_this.grid = $("#MainGrid").jqGrid({
		 			postData:{warchouseId:0},
		 			datatype: "json",			
		 			url : contextPath+'/depot/library/treeQuery.htm',//组件创建完成之后请求数据的url
					datatype : "json",//请求数据返回的类型。可选json,xml,txt
					colModel : [ //jqGrid每一列的配置信息。包括名字，索引，宽度,对齐方式.....
					             {label:"主键", name : "libraryId",sortable:false,hidden:true,key:true},
					             {label:"仓库ID", name : "warchouseId",sortable:false,hidden:true},
					             {label:"库位编号", name : 'libraryName',sortable:false,width : 140,align : "center"}, 
					             {label:"状态", name : 'libraryStatus',sortable:false,width : 80,align : "center",edittype:"select",formatter:'select', editoptions:{value:systemDict.toString(systemDict.useStatus)}}, 
					             {label:"启用状态", name : 'selectStatus',sortable:false,width : 80,align : "center",edittype:"select",formatter:'select', editoptions:{value:systemDict.toString(systemDict.selectStatus)}}, 
					             {label:"创建时间", name : 'createTime',sortable:false,width : 130,align : "center",formatter:DatFormatter} 
					           ],
		            shrinkToFit:false,   
		            autoScroll: true, 
					rowNum : 10,//一页显示多少条
					rowList : [ 10, 20, 30 ],//可供用户选择一页显示多少条
					rownumWidth: 20, //设置显示序号的宽度，默认为25  
					pager : '#MainGridPager',//表格页脚的占位符(一般是div)的id
					sortname : 'create_Time',//初始化的时候排序的字段
					sortorder : "asc",//排序方式,可选desc,asc
					mtype : "post",//向后台请求数据的ajax的类型。可选post,get
					width:page.window.grid.width-250,
					height:page.window.grid.height-30,
					onSelectRow:function(rowId){
						
					}
				});
		/*创建jqGrid的操作按钮容器*/
		/*可以控制界面上增删改查的按钮是否显示*/
		$("#MainGrid").jqGrid('navGrid', '#MainGridPager', {edit:false,del:false,add:false,search:false,refresh:false});
	},
	buttonBind:function(){//控制按钮初始化
	  var _this = this;
	  $("#selectBtn").bind("click",function(){_this.event.doSelect(_this,this)});
	  $("#cancelBtn").bind("click",function(){_this.event.doCancel(_this,this)});
	},
	event:{
		doSelect:function(_this,btn){//修改
			  var node = MainGirdCtr.getSelectRowData();
			  var materialId = $("#materialId").val();
			  if(node){
				  var params = {materialId:materialId,libraryId:node.libraryId,warchouseId:node.warchouseId};
				  $.dataPost(contextPath+'/depot/property/select.htm',params,function(result){
					  if(result.success){
						  MainGirdCtr.reLoad();
					  }else{
						  layer.msg(result.msg); 
					  }
				  });
			  }else{
				  layer.msg("选择需要修改的数据");
			  }
		  },doCancel:function(_this,btn){//修改
			  var materialId = $("#materialId").val();
			  var node = MainGirdCtr.getSelectRowData();
			  if(node){
				  var params = {materialId:materialId,libraryId:node.libraryId,warchouseId:node.warchouseId};
				  $.dataPost(contextPath+'/depot/property/cancel.htm',params,function(result){
					  if(result.success){
						MainGirdCtr.reLoad();
					  }else{
						  layer.msg(result.msg); 
					  }
				  });
			  }else{
				  layer.msg("选择需要修改的数据");
			  }
		  }
	}
});


